package org.albino.evinreisi.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.albino.evinreisi.beans.Post;


public class PostDao extends AbstractDao {
	public List<Post> getPosts() {

		String sql = "select * from post";

		System.out.println(sql);

		List<Post> posts = new ArrayList<Post>();

		List<Map<String, Object>> rows = getJdbcTemplate().queryForList(sql);

		for (Map<String, Object> row : rows) {

			Post post = new Post();

			post.setId((Long) row.get("id"));
			post.setTitle((String) row.get("title"));
			post.setBody((String) row.get("body"));
			post.setCreateDate((Date) row.get("createDate"));
			post.setTags((String) row.get("tags"));

			posts.add(post);
		}
		return posts;
	}
}
